package com.tarena.lbs.coupon.dao.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.tarena.lbs.coupon.pojo.po.CouponPO;
import com.tarena.lbs.coupon.pojo.po.CouponStockPO;
import com.tarena.lbs.coupon.pojo.query.CouponQuery;
import com.tarena.lbs.coupon.pojo.vo.CouponVO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface CouponMapper extends BaseMapper<CouponPO> {
    List<CouponPO> getStoreList(CouponQuery query);
    @Select("SELECT num FROM coupon_stock WHERE coupon_id = #{couponId}")
    Integer selectStockById(Integer couponId);
    @Insert("<script>" +
            "INSERT INTO coupon (" +
            "coupon_name, coupon_type, discount_value, max_discount_amount, " +
            "applicable, usage_limit, max_usage_limit, start_date, end_date, " +
            "status, describes, business_id, create_at, update_at, " +
            "usage_num, enable_status, exclusion_type, order_amount" +
            ") VALUES " +
            "<foreach collection='list' item='item' separator=','>" +
            "(" +
            "#{item.couponName}, #{item.couponType}, #{item.discountValue}, #{item.maxDiscountAmount}, " +
            "#{item.applicable}, #{item.usageLimit}, #{item.maxUsageLimit}, #{item.startDate}, #{item.endDate}, " +
            "#{item.status}, #{item.describes}, #{item.businessId}, #{item.createAt}, #{item.updateAt}, " +
            "#{item.usageNum}, #{item.enableStatus}, #{item.exclusionType}, #{item.orderAmount}" +
            ")" +
            "</foreach>" +
            "</script>")
    Integer insertExcel(List<CouponPO> excels);
    @Select("SELECT * FROM coupon")
    List<CouponVO> selectExcelList();
}
